#!/bin/sh
########################################################################
# Begin mysql
#
# Description : Start MysSQL Server
#
# Author      : Bruce Dubbs - bdubbs@linuxfromscratch.org
#
# Version     : BLFS 7.0
#
########################################################################

### BEGIN INIT INFO
# Provides:            mysql
# Required-Start:      $network $syslog
# Should-Start:        networkmanager wicd
# Required-Stop:       $network $syslog
# Should-Stop:         networkmanager wicd
# Default-Start:       3 4 5
# Default-Stop:        0 1 2 6
# Short-Description:   Starts MySQL server.
# Description:         Starts MySQL server.
# X-LFS-Provided-By:   BLFS
### END INIT INFO

. /lib/lsb/init-functions

#$LastChangedBy: dj $
#$Date: 2019-09-08 13:50:13 -0500 (Sun, 08 Sep 2019) $

PIDFILE=/srv/mysql/`/bin/hostname`.pid

case "$1" in
   start)
      log_info_msg "Starting MySQL daemon..."

      # Make sure the mysql user can create a socket
      mkdir -p /run/mysqld
      chown mysql.mysql /run/mysqld

      if [ -f "$PIDFILE" ]; then
         if /bin/ps -e | grep `cat $PIDFILE` | grep mysqld >/dev/null ; then
            log_warning_msg "\n   mysqld already running!" 
            exit 0
         else
            rm -f "$PIDFILE"
            if [ -f "$PIDFILE" ]; then
               log_failure_msg2
               exit 1
            fi
         fi
      fi

      /usr/bin/mysqld_safe --user=mysql 2>&1 >/dev/null &
      evaluate_retval
      ;;

   stop)
      log_info_msg "Stopping MySQL daemon..."
      killproc -p ${PIDFILE} /usr/sbin/mysqld
      evaluate_retval
      ;;

   reload)
      log_info_msg "Reloading MySQL ..."
      killproc -p ${PIDFILE} /usr/sbin/mysqld -HUP
      evaluate_retval
      ;;

   restart)
      $0 stop
      sleep 1
      $0 start
      ;;

   status)
      #statusproc /usr/sbin/mysqld
      statusproc /usr/sbin/mariadbd
      ;;

   *)
      echo "Usage: $0 {start|stop|reload|restart|status}"
      exit 1
      ;;
esac

# End /etc/init.d/mysql
